// pages/home/home.ts
Page({
  data: {
    currentTime: '09:45',
    currentTab: 'index', // home页面属于首页，所以使用index
    bannerIndex: 0,
    categories: [
      { name: '今日头条', icon: '📰', color: '#FF4444' },
      { name: '闲鱼电商', icon: '闲鱼', color: '#FFA500' },
      { name: '社群营销', icon: '👥', color: '#FF8C00' },
      { name: '淘宝电商', icon: '淘', color: '#FF8C00' },
      { name: '抖音快手', icon: '🎵', color: '#8A2BE2' },
      { name: '微信营销', icon: '💬', color: '#32CD32' },
      { name: '爆粉引流', icon: '❤️', color: '#FF8C00' },
      { name: '自媒体', icon: '👁️', color: '#0066CC' },
      { name: '社交电商', icon: '💬', color: '#FF8C00' },
      { name: '所有分类', icon: '⋯', color: '#32CD32' }
    ],
    recommendedResources: [
      {
        title: '公众号变现课:账号搭建+内容运营+商业变现+月增粉5000+变现转化提升4倍',
        image: '💻',
        type: 'course'
      },
      {
        title: '扣子工作流',
        subtitle: '道家玄学',
        image: '☁️',
        type: 'workflow'
      }
    ]
  },

  onLoad() {
    this.updateTime();
    this.startBannerTimer();
  },

  onShow() {
    this.updateTime();
  },

  updateTime() {
    const now = new Date();
    const time = now.getHours().toString().padStart(2, '0') + ':' + 
                 now.getMinutes().toString().padStart(2, '0');
    this.setData({
      currentTime: time
    });
  },

  startBannerTimer() {
    setInterval(() => {
      this.setData({
        bannerIndex: (this.data.bannerIndex + 1) % 3
      });
    }, 3000);
  },

  onSearchTap() {
    wx.showToast({
      title: '搜索功能开发中',
      icon: 'none'
    });
  },

  onBannerTap() {
    wx.showToast({
      title: '查看会员优惠',
      icon: 'none'
    });
  },

  onCategoryTap(e: any) {
    const category = e.currentTarget.dataset.category;
    wx.showToast({
      title: `进入${category}分类`,
      icon: 'none'
    });
  },

  onResourceTap(e: any) {
    const resource = e.currentTarget.dataset.resource;
    wx.showToast({
      title: `查看${resource.title}`,
      icon: 'none'
    });
  },

  onPartnerTap() {
    wx.showToast({
      title: '开通分站合伙人',
      icon: 'none'
    });
  },

  onEarningTap() {
    wx.showToast({
      title: '了解赚钱模式',
      icon: 'none'
    });
  },

  onTabTap(e: any) {
    const page = e.currentTarget.dataset.page;
    if (page === 'home') {
      return; // 当前页面，不需要跳转
    }
    
    const pages = {
      'courses': '/pages/courses/courses',
      'member': '/pages/member/member',
      'profile': '/pages/profile/profile'
    };
    
    wx.navigateTo({
      url: pages[page as keyof typeof pages]
    });
  }
});
